package models;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ItemModel extends AbstractModel
{	
	public boolean insert(Integer upc, String title, String type,String category, String company, Integer year, Integer sellPrice)
	{	
		try {
			ps = con.prepareStatement("INSERT INTO Item VALUES (?,?,?,?,?,?,?)");
			ps.setInt(1,upc);
			ps.setString(2,title);
			ps.setString(3,type.toUpperCase());
			ps.setString(4,category.toUpperCase());
			ps.setString(5, company);
			ps.setInt(6,year);
			ps.setInt(7, sellPrice);
			
			return wrapUp();
		} catch(SQLException ex) { return registerException(ex); }
	}

	public boolean delete(int upc)
	{	
		try
		{
			ps = con.prepareStatement("DELETE FROM Item WHERE upc = ?");
		    ps.setInt(1, upc);
		    return wrapUp();
		} 
		catch (SQLException ex)
		{ 
			return registerException(ex); 
		}
	}
	
	// called by the show() method of the associated controller
	public ResultSet show()
	{	
		return super.show("Item"); 
	}
}
